package com.bytecollege.service.Impl;




import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bytecollege.mapper.CremarkMapper;
import com.bytecollege.model.Course;
import com.bytecollege.model.Cremark;

import com.bytecollege.service.CremarkService;

import com.bytecollege.vo.MyCremarkVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName: CremarkService
 * @Description: 课程评论的实现类
 * @Author: Sun
 * @Date: 2022/10/19 16:53
 */
@Service
public class CremarkServiceImpl extends ServiceImpl<CremarkMapper, Cremark> implements CremarkService {
    @Autowired
    private CremarkMapper cremarkMapper;

    /**
     * 查询课程评论
     * @return
     */
    public List<Cremark> getCremark(Page<Cremark> page, Integer courseId){
        QueryWrapper<Cremark> wrapper = new QueryWrapper<>();
        cremarkMapper.selectPage(page,wrapper.eq("course_id",courseId));
        return page.getRecords();
    }

    /**
     * 查询单个课程评论
     * @param cremarkId
     * @return
     */
    public Cremark getCremarkOne(Integer cremarkId){
        return cremarkMapper.selectById(cremarkId);
    }

    /**
     * 添加课程评论
     * @param cremark
     * @return
     */
    public int addCremark(Cremark cremark){
        return cremarkMapper.insert(cremark);
    }

    /**
     * 修改课程评论
     * @param cremark
     * @return
     */
    public int modCremark(Cremark cremark){
        return cremarkMapper.updateById(cremark);
    }


    /**
     * 根据用户id查询所有的课程评论
     * @return
     */
    public List<MyCremarkVO> getCremarkById(Page<MyCremarkVO> page, Integer userId){
        return  cremarkMapper.cremarkList(page,userId);
    }

    /**
     * 删除评论
     * @param id
     * @return
     */

    public int delCremarkById(Integer id){
        return cremarkMapper.deleteById(id);
    }

    public Integer getCremarkNum(){
        return cremarkMapper.getCremarkNum();
    }
}
